package com.jinkaimen.kqb.service;

import android.app.IntentService;
import android.content.Intent;

import com.ht.baselibs.bean.BaseGetBean;
import com.ht.baselibs.utils.LogUtils;
import com.ht.baselibs.utils.SharedPreferencesUtils;
import com.igexin.sdk.PushManager;
import com.jinkaimen.kqb.constant.Constants;
import com.jinkaimen.kqb.manager.ApiManager;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Response;

public class UploadClientIdSevice extends IntentService {

    public UploadClientIdSevice() {
        super("com.ht.baselibs.services.DownloadApkSevice");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        String cid = PushManager.getInstance().getClientid(UploadClientIdSevice.this);

        if (cid != null) {
            SharedPreferencesUtils.put(Constants.CID, cid);
            Call<BaseGetBean> uploadClientId = ApiManager.getApi().clientid(
                    "HSS001002",
                    cid
            );

            try {
                Response<BaseGetBean> response = uploadClientId.execute();
                if (response.isSuccessful()) {
                    LogUtils.error("上传clientId成功");
                } else {
                    LogUtils.error("上传clientId失败");
                }
            } catch (IOException e) {
                e.printStackTrace();
                LogUtils.error("上传clientId失败" + e.getMessage());
            }
        }
    }

}
